package com.ratp.expertisetechnique;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.widget.EditText;

import com.ratp.bean.Expertise;
import com.ratp.bean.UtilsBean;
import com.ratp.composants.CustomTextWatcher;

public class Pneumatique extends Activity {
	private EditText editPneuma1;
	private EditText editPneuma2;
	private EditText editPneuma3;
	private EditText editPneuma4;
	private EditText editPneuma5;
	private EditText editPneuma6;
	private EditText editComiteMontage;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pneumatique);
		initVariables();
		initEcouteurs();
	}

	private void initVariables() {

		editPneuma1 = (EditText) findViewById(R.id.editPneuma1);
		editPneuma2 = (EditText) findViewById(R.id.editPneuma2);
		editPneuma3 = (EditText) findViewById(R.id.editPneuma3);
		editPneuma4 = (EditText) findViewById(R.id.editPneuma4);
		editPneuma5 = (EditText) findViewById(R.id.editPneuma5);
		editPneuma6 = (EditText) findViewById(R.id.editPneuma6);
		editComiteMontage = (EditText) findViewById(R.id.editComiteMontage);

		Expertise expertise = UtilsBean.getExpertiseInstance();

		editPneuma1.setText(String.valueOf(expertise.getPneuma1()));
		editPneuma2.setText(String.valueOf(expertise.getPneuma2()));
		editPneuma3.setText(String.valueOf(expertise.getPneuma3()));
		editPneuma4.setText(String.valueOf(expertise.getPneuma4()));
		editPneuma5.setText(String.valueOf(expertise.getPneuma5()));
		editPneuma6.setText(String.valueOf(expertise.getPneuma6()));
		editComiteMontage.setText(expertise.getConformiteMontage());
	}

	private void initEcouteurs() {
		editPneuma1.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				String value = s.toString();
				if (value.length() != 0) {
					UtilsBean.getExpertiseInstance().setPneuma1(
							Integer.parseInt(value));
				}

			}
		});
		editPneuma2.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				String value = s.toString();
				if (value.length() != 0) {
					UtilsBean.getExpertiseInstance().setPneuma2(
							Integer.parseInt(value));
				}
			}
		});
		editPneuma3.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				String value = s.toString();
				if (value.length() != 0) {
					UtilsBean.getExpertiseInstance().setPneuma3(
							Integer.parseInt(value));
				}
			}
		});
		editPneuma4.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				String value = s.toString();
				if (value.length() != 0) {
					UtilsBean.getExpertiseInstance().setPneuma4(
							Integer.parseInt(value));
				}
			}
		});
		editPneuma5.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				String value = s.toString();
				if (value.length() != 0) {
					UtilsBean.getExpertiseInstance().setPneuma5(
							Integer.parseInt(value));
				}
			}
		});
		editPneuma6.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				String value = s.toString();
				if (value.length() != 0) {
					UtilsBean.getExpertiseInstance().setPneuma6(
							Integer.parseInt(value));
				}
				else{
					UtilsBean.getExpertiseInstance().setPneuma6(0);
				}
			}
		});
		editComiteMontage.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				UtilsBean.getExpertiseInstance().setConformiteMontage(
						s.toString());
			}
		});
	}
}
